package practice1_100;

import java.util.*;


public class BBBB {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int len=sc.nextInt();
        String str=sc.next();
        Map<Integer,Integer> map=new HashMap<>();
        StringBuffer buffer=new StringBuffer();
        for (int i = 1; i <= 9; i++)  map.put(i, sc.nextInt());
        List<String> strings=new ArrayList<>();
        boolean[] is=new boolean[len];//为真可以连续
        for (int i = 0; i < len; i++) {
            if(str.charAt(i)-'0'>map.get(str.charAt(i)-'0'))is[i]=true;
        }
        int start=0,end=0;
        while (end<len){
            if(!is[end]) {
                buffer.append(map.get(str.charAt(end)-'0'));
            }
            else {
                if(start+1==end||start==end)
                    strings.add(str.substring(0,len));
                else  strings.add(str.substring(0,start+1)+buffer.toString()+str.substring(end,len));
                buffer=new StringBuffer();
               start=end;
            }
            end++;
        }
        Collections.sort(strings);
        System.out.println(strings.get(strings.size()-1));
    }
}
